<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://mail">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="../menu.xsl" />
	<xsl:include href="../common/form.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/mail.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/forms.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/mail.js" />
			<script type="text/javascript" src="{$baseURI}/js/simpleEditor.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />
			
			<!-- Header -->
			<div id="header">
				<xsl:call-template name="logo" />
				
				<!-- Menu -->
				<xsl:call-template name="menu" />
			</div>
			<!-- /Header -->
			
			<!-- Blocks -->
			<div id="blocks">
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
				</div>
			</div>
			<!-- // Blocks -->
			
			<!-- Content -->
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			<!-- // Content -->
			
			<!-- Address -->
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		
		<h1><a href="{$baseURI}/mail">&labelMail;</a> → &labelNew;</h1>

		<form action="{$baseURI}/mail/write/send" method="post" enctype="multipart/form-data">
			<xsl:for-each select="form/field">
					<xsl:apply-templates select="." />
			</xsl:for-each>
			<p>
				<input type="submit" value="&labelSend;" />		
			</p>
		</form>
	</xsl:template>
	
	<xsl:template match="form/field[@character='integer' and @name='addressed_user_id']">
		<div class="form_field">
			<div class="form_field_label">&labelTo;:</div>
			<div class="form_field_input">
				<select id="blog_select" class="form_input_guide" name="data[{$formPrefix}][{@name}]">
					<option value="0">&labelSelectTo;</option>
					
					<xsl:apply-templates select="document(concat('xmodule://mail/getUserFriendsSelection/', value))/data/response/object" mode="friends-options">
						<xsl:sort select="property[@name='user_name']/value" />
					</xsl:apply-templates>
					
				</select>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- FRIENDS OPTION -->
	<xsl:template match="object[@type='friend']" mode="friends-options">
		<option>
			<xsl:if test="@selected = '1'">
				<xsl:attribute name="selected"><xsl:text>selected</xsl:text></xsl:attribute>
			</xsl:if>
			<xsl:attribute name="value">
				<xsl:value-of select="property[@name='friend_id']/value" />
			</xsl:attribute>
			<xsl:value-of select="property[@name='user_name']/value" />
		</option>
	</xsl:template>
	
</xsl:stylesheet>